package com.itheima.health.controller.mobile;

import com.itheima.health.common.MessageConst;
import com.itheima.health.pojo.entity.Order;
import com.itheima.health.pojo.result.Result;
import com.itheima.health.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/mobile/order/")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;
    @PostMapping ("submit")
    public Result submit(@RequestBody Map map) {
        log.info("体检人预约");
        //调用短信工具类获取验证码
        String Code = "123456";
        //获取前端传入的验证码
        String validateCode = (String) map.get("validateCode");
        if (validateCode.equals(Code)) {
            log.info("验证成功");
        Order order=orderService.order(map);
            return new Result(true, MessageConst.ACTION_SUCCESS,order);
        }
        //调用体检预约服务
        return new Result(false,MessageConst.ORDER_SUCCESS);
    }
    @GetMapping("findById")
    public Result findById(Integer id) throws Exception {
        log.info("根据预约人id查询订单数据");
        Map map=orderService.findById(id);
        return new Result(true,MessageConst.QUERY_SETMEAL_SUCCESS,map);
    }
}
